/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/*!
	\file XMLtoData.h
	\brief header file for XML parser

	                  \author Jack Elston
	           $Date: 2006/10/25 13:34:45 $
*/

#ifndef __PICCOLOPARSER_H
#define __PICCOLOPARSER_H

#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>

#include "String.h"
#include "command.h"
#include "queue.h"
#include "type_defs.h"
#include "threadedPipe.h"
#include "shmStruct.h"

#include "CRC.h"
#include "stream.h"
#include "Queue.h"
#include "FlightPlan.h"
#include "StreamPackets.h"
#include "TimeBase.h"
#include "AutopilotPacket.h"
#include "AutopilotPacketGnd.h"
#include "Network.h"

#define USER_WAYPOINT_MIN 30
#define USER_WAYPOINT_MAX 89

//-- Table Mountain
#define USER_MIN_ALT  1700
#define USER_MAX_ALT  1800
#define USER_MIN_LAT  40.138 
#define USER_MAX_LAT  40.15
#define USER_MIN_LON -105.246
#define USER_MAX_LON -105.235

#define LOOP_CMD_TAS  0
#define LOOP_CMD_ALT  1
#define LOOP_CMD_BANK 2

//-- Pawnee
//#define USER_MIN_ALT 1650 // should be more than 100 [m] agl
//#define USER_MAX_ALT 1800 // should be close to 1000 [ft] agl
//#define USER_MIN_LAT   40.6103 
//#define USER_MAX_LAT   40.8720
//#define USER_MIN_LON -104.6578
//#define USER_MAX_LON -104.3358

class PiccoloParser : public ThreadedPipe
{
private:

	int init;
	void parse(const Command &cmd); // parse our command set
	int parse(int num);             // parse piccolo command set

	void sendTelem(void);

	FPMask_t active_wp_mask;  // points on piccolo, tracked and maintained locally
	FPMask_t sent_mask;       // points that have been downloaded
	FPMask_t waypoint_mask;   // woring masked used to detect receipt of onboard plans

	FPPoint_t piccolo_waypoints[NUM_FP_POINTS]; // flight plan on piccolo, maintained locally

  bool lost_comm;
	//in_addr  fp_src_addr;
	bool gs_backup;

public:
	PiccoloParser(String name, bool gs_backup = false);
	~PiccoloParser() {};

	void update();
};

#endif
